package pl.mcnova.model.table;

import java.text.SimpleDateFormat;
import java.util.List;

import pl.mcnova.model.dao.MailDAO;
import pl.mcnova.model.entity.Mail;

public class ContractorMailTableModel extends TableModel<Mail> {

	private MailDAO mailDAO;

	public ContractorMailTableModel() {
		super();
		mailDAO = new MailDAO();
	}

	public ContractorMailTableModel(List<Mail> mails) {
		super(mails);
		mailDAO = new MailDAO();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		if (rowIndex > -1 && rowIndex < data.size() && columnIndex > -1 && columnIndex < classNames.length) {

			if (data.get(rowIndex) == null) {
				if (columnIndex == 0)
					return rowIndex + 1;
				else
					return null;
			}

			Mail m = data.get(rowIndex);

			switch (columnIndex) {
			case 0:
				SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy kk:mm");
				return format.format(m.getDate());
			case 1:
				return m.getSubject();
			default:
				return null;
			}
		} else {
			return null;
		}
	}

	@Override
	public void setColumns() {
		columnNames = new String[] { "Data", "Temat" };
		classNames = new Class[] { String.class, String.class };
	}

}
